﻿//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc. 
/****************************************************************************/

/**
* 入口模块，相对于Main函数
*/

define(function (require, exports, module) {
    //   var FXREADER = require('./FXReader');
    var FXREADER = require('./FXReader');
    require('./Config');
    window.onresize = function () {
        if (FXREADER != null && FXREADER.AppInstance != null)
            FXREADER.AppInstance.OnResize();
    };

    exports.InitReaderApp = function (fileID, fileName, mainFrameID,dType) {
    	fileName = "Test File Long Long Long Name.pdf";
        var CReaderApp = require('./WebReaderApp');
        require('./Common');
        var bDebug = false;
        try {
            if (/debug/i.test(location.hash)) {
                bDebug = true;
            }
            var jqMainFrm = $("#" + mainFrameID);
            var leftPanelID = mainFrameID + "_leftPanel";
            var topPanelID = mainFrameID + "_topPanel";
            var bottomPanelID = mainFrameID + "_bottomPanel";
            jqMainFrm.append("<div id='" + topPanelID + "' class='fwr_top_layer_2 fwr_mainfrm_top' style='position:absolute;left:0px;top:0px;width:100%;'></div>");
            jqMainFrm.append("<div id='" + leftPanelID + "' class='fwr_top_layer' style='position:absolute;left:0px;top:0px;'></div>");
            jqMainFrm.append("<div id='" + bottomPanelID + "' class='fwr_top_layer_2 fwr_mainfrm_bottom' style='display:none' ></div>");

			var documentLoader = new FXREADER.IMG.DocumentLoader();//这个类还没加，需要实现webreader里的doc数据下载
			if(dType == 1){
				documentLoader = new FXREADER.HTML5.DocumentLoader();
			}

            FXREADER.AppInstance = new WebReaderApp(fileID, fileName, mainFrameID, leftPanelID, topPanelID,bottomPanelID,documentLoader);
            //名称必须是AppInstance，这样在全局范围内可以引用这个对象
            FXREADER.AppInstance.SetDebugMode(bDebug);
            return FXREADER.AppInstance;
        }
        catch (ex) {
            if (bDebug)
                throw ex;
        }
    };

    exports.SetPluginConfig = function (plugConfig) {
        if (plugConfig == null)
            return;
        var pluginsConfigCookie = FXREADER.Config.Plugins.load;
        for (var key in FXREADER.Config.Plugins.flag) {
            if (pluginsConfigCookie[key] != null && plugConfig & FXREADER.Config.Plugins.flag[key])
                pluginsConfigCookie[key] = true;
            else
                pluginsConfigCookie[key] = false;
        }
    };

    exports.InitInstance = function () {
        try {
            //加载用到的插件，但不初始化;
            FXREADER.AppInstance.CallAllPlugin();
            //实例化之前的事件;
           /* var CVerfyForward_InstanceEventHandler = require('./VerfyForward/CVerfyForward_InstanceEventHandler');
            var instanceHandler = new CVerfyForward_InstanceEventHandler();
            FXREADER.AppInstance.RegisterInstanceEventHandler(instanceHandler);*/
            //按顺序执行，到最后一个执行appInstance.InitInstance;
            FXREADER.AppInstance.OnBeforeInstance();
        }
        catch (ex) {
            if (FXREADER.AppInstance.IsDebugMode())
                throw ex;
        }
    };
    // InitReaderApp();

});